<!DOCTYPE HTML>
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta name="author" content="PNT" />

	<title>Administrator</title>
    <link rel="stylesheet" href="../css/admin.css" />
    <script type="text/javascript" charset="utf-8" src="../js/tiny_mce/tiny_mce.js"></script>
    <script type="text/javascript" charset="utf-8" src="../js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="../js/jquery-ui-1.7.2.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="../js/jquery.validate.min.js"></script>
    <script type="text/javascript">
    
        $(document).ready(function(){
            $("#login-form").validate();
        });
    
    </script>

</head>

<body>

<?php
@session_start();
include("../includes/config.php");


if (isset($_POST['submit'])) {
    $username = urldecode($_POST['username']);
    $password = md5(urldecode($_POST['password']));
    $sql = "select * from users where username = '$username' and password = '$password' and level = 2";
    $data = $db->fetch_array($db->query($sql));
    
    if (!empty($data)) {
        $_SESSION['login'] = 1; // true
        $_SESSION['level'] = 2;
        $_SESSION['user_id'] = $data['id'];
        $_SESSION['username'] = $data['username'];
        header("Location: index.php");
    } else {
?>
        <script type="text/javascript">
            alert('Tài khoản hoặc mật khẩu không đúng !');
        </script>
<?php
    }
}

?>
<div id="login">
    <form id="login-form" method="post" action="">
        <p>
            <label class="login-label">Tài khoản</label>
            <input name="username" size="30" type="text" class="required" />
        </p>
        <p>
            <label class="login-label">Mật khẩu</label>
            <input name="password" size="30" type="password" class="required" />
        </p>
        <p>
            <input type="submit" name="submit" value="Đăng nhập" class="button" />
            <input type="reset" value="Nhập lại" class="button" />
        </p>
    </form>
</div>
</body>

</html>